<?php
//自定义系统模型
//管理数据表
//管理字段
//添加模型

class ModelAction extends CommonAction{
	
	//管理数据表
	//显示添加的数据表
	public function listtable(){
		//$Table=M('table');
		$list=M('table')->select();
		$this->assign('list',$list);
		$this->display();
	}
	
	public function edittable(){
		//dump($_GET['tid']);
		$r=D('table')->where("tid=".$_REQUEST['tid'])->find();
		$this->assign('r',$r);
		$this->display();
	}
	
	public function addtable(){
		$this->display();
	}
	
	public function deltable(){
		$Table=D('table');
		$Table->where("tid=".$_REQUEST['tid'])->delete();
	}	
	
	public function act_addtable(){
		$Table=D('table');
		//$_POST['tname']=C('DB_PREFIX').$_POST['tname'];
		if(!$Table->create()){
			$this->error($this->getError());
		}
		die(1);
		//默认建表
		$sql="CREATE TABLE IF NOT EXISTS `".C('DB_PREFIX')."_xxx` (
			`id` int(11) NOT NULL AUTO_INCREMENT,
			PRIMARY KEY (`id`)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
			";
		$Table->query($sql);
		//缓存相关
		
		//添加记录
		$Table->add();		
	}
		
	public function act_edittable(){
		dump($_POST);
		$Table=D("Table");
		dump($Table);
		if(!$Table->create()){
			$this->error($Table->getError());
		}
		$Table->save();
		$this->success('成功修改数据表');
	}
	
	//显示和数据表绑定的模型
	public function listmodel(){
		$tablelist=M('table')->select();
		
	}
	
	public function addmodel(){
		
	}	
	
	public function editmodel(){
		
	}
	
	public function delmodel(){
		
	}
	
	//数据表字段管理
	public function listfield(){
		$tbname=$_REQUEST['tbname'];
		$this->assign('tbname',$tbname);
		$this->assign('list',M('Field')->where("tid=".$_REQUEST['tid'])->select());
		$this->display();
	}
	
	public function editfield(){
		$tbname=$_REQUEST['tbname'];
		$this->assign('tbname',$tbname);
		$this->assign('r',M('Field')->where("fid=".$_REQUEST['fid'])->find());
		$this->display();
	}
	
	public function addfield(){
		$tbname=$_REQUEST['tbname'];
		$this->assign('tbname',$tbname);
		//$this->assign('r',M('Field')->where("fid=".$_REQUEST['fid'])->find());
		$this->display();
	}

	public function act_addfield(){
		$Field=D('Field');
		$Field->creat();
		var_dump($Field);
	}
	
	public function act_editfield(){
		$tbname=$_REQUEST['tbname'];
		$this->assign('tbname',$tbname);
		//$this->assign('r',M('Field')->where("fid=".$_REQUEST['fid'])->find());
		$this->display();
	}	
}